
package com.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bean.ResponseBean;
import com.dao.MovieListDAO;
import com.dao.ProgramCategoryDAO;
import com.pojo.ProgramCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Service
public class DyTypeService extends ServiceImpl<ProgramCategoryDAO, ProgramCategory> {

    @Autowired
    private MovieListDAO movieListDAO;
    /**
     * 获取所有可用的类型
     *
     * @return
     */
    public List findAll() {
        QueryWrapper q = new QueryWrapper();
        q.eq("state", 1);
        q.orderByAsc("sort");
        List list = list(q);

        QueryWrapper qTuijian = new QueryWrapper();
        qTuijian.eq("home_pag_recommendation", 1);
        //condition参数是否将该sql语句（像in()、like()）加在总sql语句上
        int count = movieListDAO.selectCount(qTuijian);
        if (count>0) {


            ProgramCategory tuijian = new ProgramCategory();
            tuijian.setId("0");
            tuijian.setCreationTime(new Date());
            tuijian.setProgramName("最新推荐");
            tuijian.setState(1);
            list.add(0,tuijian);
        }

        return list;
    }

    public void xiajiaExpire() {
        movieListDAO.xiajiaExpire();
    }
}
